<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * 文件管理
 */
namespace CMS\Controller;
use Common\Controller\AdminController;

/**
 * 文件管理控制器
 */
class FileController extends AdminController{
	
	/**
	 * 文件管理
	 */
    public function Manage(){
		
		action_log('admin_file_manage');//行为记录
		
		//配置页面
		common_public()->assign_page('文件管理');
		
		//实例化数据库
		$m_common_upload_type = M('common_upload_type');
		$m_common_user = M('common_user');
		$m_common_upload = M('common_upload');
		
		//获得查询文件类型
		$tid = I('param.tid')?I('param.tid'):0;
		
		$type = $m_common_upload_type->where('status=1')->select();
		
		if($tid!=0){
			
			foreach($type as $ti=>$tk){
				
				if($type[$ti]['id']==$tid){
					
					$type[$ti]['selected'] = "selected";
				}
			}
			$map['type'] =$tid;
		}
		
		//selected="selected"
		$this->assign('type',$type);
		$this->assign('types',$type);
		
		
		//查看指定用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =$uid;
		}
		
		//selected="selected"
		$this->assign('uid',$uid);
		
		//上传开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
			
		}else{
			
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		//查询文件大小区间
		$begin_size = I('param.begin_size');
		$end_size = I('param.end_size');
		if($begin_size != null and $end_size != null){
			
			$map['size']  = array(array('egt',$begin_size),array('elt',$end_size),'and'); 
			
		}
		
		$this->assign('begin_size',$begin_size);
		$this->assign('end_size',$end_size);
		
		
		//默认首页
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_common_upload->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		$count      = $m_common_upload->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		//查询关联信息
		foreach($list as $i=>$k){
			
			$tmap['id'] = $list[$i]['type'];
			
			$tdata = $m_common_upload_type->where($tmap)->find();
			
			$umap['id'] = $list[$i]['uid'];
			
			$udata = $m_common_user->where($umap)->find();
			
			$list[$i]['title_type'] = $tdata['title'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
		
		}
	
		$this->assign('list',$list);
		
		$this->display();
		
	}
	
}